#pragma once

#include "Deck.h"

Deck::Deck()
{
}

Deck::~Deck()
{
}

void Deck::Reset()
{
	int value = 2;

	for (int i=0; i < 52; i++)
	{
		card[i].value = value;
		value++;

		if(i < 13)
			card[i].suit = 0; // Diamonds
		else if(i < 26)
			card[i].suit = 1; // Clubs
		else if(i < 39)
			card[i].suit = 2; // Hearts
		else 
			card[i].suit = 3; // Spades

		if (value > 14)
			value = 2;
	}

	
	remaining = 52;
}

int Deck::GetValue()
{
	int value, index;

	//if there are no cards left then it'll draw a blank card
	if (remaining <= 1)
		return 0;
	
	index = (1 + rand() % (remaining -1));
	value = card[index].value;

	//the card is gone, so remove it move everything up
	for (int i=index; i < remaining - 1; i++)
	{
		card[i] = card[i+1];
	}

	remaining--;

	return value;
}

Card Deck::GetCard()
{
	Card blank;
	int index;

	//init card
	blank.value = 1;
	blank.suit = 4;

	//if there are no cards left then it'll draw a blank card
	if (remaining <= 1)
		return blank;
	
	index = (1 + rand() % (remaining -1));
	Card get = card[index];

	//the card is gone, so remove it move everything up
	for (int i=index; i < remaining - 1; i++)
	{
		card[i] = card[i+1];
	}

	remaining--;

	return get;
}